package com.example.srm.common.filter;

import lombok.extern.slf4j.Slf4j;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author pfk
 * @creatTime 2022/01/20 11:48
 * @describe 全局过滤器
 */
@WebFilter("/*")
@Slf4j
public class MyFilter implements Filter {


    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.info("进入拦截器");
        HttpServletRequest request = (HttpServletRequest)servletRequest;
        HttpServletResponse response = (HttpServletResponse)servletResponse;
        response.setContentType("text/html;charset=UTF-8");
        String uri = request.getRequestURI();
        //过滤静态资源
        if (uri.contains(".")){
            filterChain.doFilter(request,response);
            return;
        }
        if (uri.contains("/login")){
            filterChain.doFilter(request,response);
            return;
        }
        filterChain.doFilter(request,response);




    }
}
